#include "Timer.h"

Timer::Timer() {
	startTicks = 0;
	pausedTicks = 0;
	paused = false;
	started = false;
}

void Timer::start() {
	started = true;
	paused = false;
	startTicks = SDL_GetTicks();
}

void Timer::stop() {
	paused = false;
	started = false;
}

void Timer::pause() {
	if ((started == true) && (paused == false)) {
		paused = true;
		pausedTicks = SDL_GetTicks() - startTicks;
	}
}

void Timer::unpause() {
	if (paused == true) {
		paused = false;
		startTicks = SDL_GetTicks() - pausedTicks;
		pausedTicks = 0;
	}
}

int Timer::getTicks() {
	if (started == true) {
		if (paused == true) {
			return pausedTicks;
		}
		else {
			int t = SDL_GetTicks() - startTicks;
			return t;
		}
	}
	return 0;
}
